from sqlalchemy import Column, Integer, String
from SqlClass import DbSession, Base


class digiccy_member(Base):
    __tablename__ = 'digiccy_member'  # 表名
    id = Column(Integer, primary_key=True)  # id:int类型,是主键
    api_key = Column(String)
    api_secret = Column(String)
    balance = Column(Integer)

    def consume(self, num):
        session = DbSession()
        self.balance -= num
        session.query(self).filter_by(id=self.id).update("balance", self.balance)
        session.commit()
        session.close()
